module Words where

import Char

-- Typed from Haskell The Craft of Functional Programming Second Edition, Simon Thompson

whitespace = ['\n','\t',' ', '\\']
slash = ['\n','\\']

getWord :: String -> String
getWord [] = []
getWord (x:xs)
	| elem x whitespace = []
	| otherwise 		= x : getWord xs

dropWord :: String -> String
dropWord [] = []
dropWord (x:xs)
	| elem x whitespace = (x:xs)
	| otherwise			= dropWord xs

dropSpace :: String -> String
dropSpace [] = []
dropSpace (x:xs)
	| elem x whitespace	= dropSpace xs
	| otherwise			= (x:xs)

splitWords :: String -> [String]
splitWords s = split (dropSpace s)

split :: String -> [String]
split [] = []
split s
	= (getWord s) : split (dropSpace (dropWord s))

	
-- Variation of the above, used to capture vertex info

getWord2 :: String -> String
getWord2 [] = []
getWord2 (x:xs)
	| elem x slash 	= []
	| otherwise 	= x : getWord2 xs

dropWord2 :: String -> String
dropWord2 [] = []
dropWord2 (x:xs)
	| elem x slash 	= (x:xs)
	| otherwise		= dropWord2 xs

dropSpace2 :: String -> String
dropSpace2 [] = []
dropSpace2 (x:xs)
	| elem x slash	= dropSpace2 xs
	| otherwise		= (x:xs)

splitWords2 :: String -> [String]
splitWords2 s = split2 (dropSpace2 s)

split2 :: String -> [String]
split2 [] = []
split2 s
	= (getWord2 s) : split2 (dropSpace2 (dropWord2 s))